package com.sojson.project.controller.param.verify;

import java.sql.SQLException;

import com.sojson.enums.EAddrIsDefault;
import com.sojson.project.entity.po.Addresses;
import com.sojson.result.Result;
import com.sojson.util.MatcheUtil;
import com.sojson.util.StringUtil;

/**
 * 收货地址表参数验证
 * 
 * @author liu
 * @date 2021-03-16
 */
public class AddressesParamVerify {

    /**
     * 单条插入
     * 
     * @param mean
     * @return
     */
    public static Result<?> insert(Addresses addresses) {
        if (StringUtil.isBlank(addresses.getName())) {
            return Result.fail("姓名不能为空！");
        }
        String mobile = addresses.getMobile();
        if (StringUtil.isBlank(mobile)) {
            return Result.fail("手机号不能为空！");
        }
        if (!MatcheUtil.isMobile(mobile)) {
            return Result.fail("手机号格式错误！");
        }
        if (StringUtil.isBlank(addresses.getProvince())) {
            return Result.fail("省不能为空！");
        }
        if (StringUtil.isBlank(addresses.getCity())) {
            return Result.fail("市不能为空！");
        }
        if (StringUtil.isBlank(addresses.getArea())) {
            return Result.fail("区不能为空！");
        }
        if (StringUtil.isBlank(addresses.getAddress())) {
            return Result.fail("详细地址不能为空！");
        }
        if (StringUtil.isBlank(addresses.getIsDefault())) {
            addresses.setIsDefault(EAddrIsDefault.NO.getCode());
        }

        return Result.success();
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param addresses
     * @return
     * @throws SQLException
     */
    public static Result<?> updatePartialById(Addresses addresses) {
        if (StringUtil.isBlank(addresses.getId())) {
            return Result.fail("ID不能为空！");
        }
        String mobile = addresses.getMobile();
        if (StringUtil.isNotBlank(mobile) && !MatcheUtil.isMobile(mobile)) {
            return Result.fail("手机号格式错误！");
        }

        return Result.success();
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     * @throws SQLException
     */
    public static Result<?> findById(Integer id) {
        if (StringUtil.isBlank(id)) {
            return Result.fail("ID不能为空！");
        }

        return Result.success();
    }

}